-
Notifications
You must be signed in to change notification settings - Fork 77
chore: refactor unimplemented method test macro #2138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: refactor unimplemented method test macro #2138
Conversation
8e18ef8 to
d70ee30
Compare
parthea
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added non-blocking comments. Feel free to follow up in a later PR
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
| # and should replace it once we cover all the test cases in it here. | ||
| #} | ||
| {% macro rest_transport_specific_tests(service, transport, is_async) %} | ||
| {% if 'rest' in transport %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support having this rest-checking failsafe here, it but it does seem somewhat redundant/uninformative. At the very least least you should error if transport is wrong:
{% if 'rest' not in transport %}
{{ raise GenerationError }}
{% else %}
...
{% endif %}
More generally, though, I would support changing the name of this macro so it can be used for both REST and gRPC. Obviously we would do the gRPC refactoring later, not in this PR. WDYT? If this sounds feasible, consider editing as below, and let's file an issue. This would help us ensure we're thorough in our tests and consistent for both transports.
{% macro run_tests_for_config(service, transport, is_async) %}
{% if 'grpc' in transport %}
{{ raise GenerationError("gRPC tests will be moved here") }}
{% else %} {# rest #}
...
{% endif %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I've filed an issue and linked it to follow up with adding gRPC tests here as suggested.
- I've updated the macro name to be more generic.
I don't think we need to raise a generation error for gRPC tests since it would add unnecessary toil in the test suite (i.e. this suite shouldn't be run against gRPC transport which is why we're skipping for it).
I think It's fine to skip generation for it as long as we have a tracking bug to include gRPC tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I don't think we need to raise a generation error for gRPC tests since it would add unnecessary toil in the test suite (i.e. this suite shouldn't be run against gRPC transport which is why we're skipping for it).
The idea is to just have a fail-safe to ensure we're indeed skipping it. It protects us from our own future programming errors. I've found this defensive practice valuable.
Not a blocker for this PR, but I still say it's a nice to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's nice to have a fail-safe. Let's sync on this offline and we can address this as a follow up if needed.
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
| {# NOTE: We will keep updating this method as we add support for methods in async REST. #} | ||
| {% macro is_rest_unsupported_method(method, is_async) %} | ||
| {%- if method.client_streaming or is_async -%} | ||
| {{'True'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you have the macro return True and False as booleans rather than strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Macros can only return strings and this is the best thing I could come up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, right.
I guess what I was thinking would be more clearly described in terms of defining the functionality of this macro in Python proper (eg def is_supported(method, is_async):...), so the invocations below would call something like {% if is_supported(method, is_async) %} ... {% endif %} without the string comparison, which grates a little. That would be more elegant. But if you expect this macro to be temporary anyhow, we can skip it. What you have is fine.
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
| {# NOTE: We will keep updating this method as we add support for methods in async REST. #} | ||
| {% macro is_rest_unsupported_method(method, is_async) %} | ||
| {%- if method.client_streaming or is_async -%} | ||
| {{'True'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, right.
I guess what I was thinking would be more clearly described in terms of defining the functionality of this macro in Python proper (eg def is_supported(method, is_async):...), so the invocations below would call something like {% if is_supported(method, is_async) %} ... {% endif %} without the string comparison, which grates a little. That would be more elegant. But if you expect this macro to be temporary anyhow, we can skip it. What you have is fine.
| # and should replace it once we cover all the test cases in it here. | ||
| #} | ||
| {% macro rest_transport_specific_tests(service, transport, is_async) %} | ||
| {% if 'rest' in transport %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I don't think we need to raise a generation error for gRPC tests since it would add unnecessary toil in the test suite (i.e. this suite shouldn't be run against gRPC transport which is why we're skipping for it).
The idea is to just have a fail-safe to ensure we're indeed skipping it. It protects us from our own future programming errors. I've found this defensive practice valuable.
Not a blocker for this PR, but I still say it's a nice to have.
| {### test cases section ends ###} | ||
| {% endfor %} | ||
| {### Test generation for all methods ends ###} | ||
| {{ rest_method_initialize_client_test(service, transport_name, is_async) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for having a policy!
I was also referring to consistency with pre-existing macros, even before this PR. Making macro naming consistent overall would be a nice cosmetic clean-up, but obviously not critical. We can follow up at some point (though honestly, it seems like this will be near the bottom of our list for a good time, since it's not that important).
This PR refactors the macro for testing not implemented methods of rest transport.
For now, the macro is guarded and only generates tests for sync REST not implemented methods. Once we implement the relevant logic in async rest, the guard can be removed. (This will be addressed in a follow up PR).